// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  modules: [
    "@pinia/nuxt",
    "@nuxtjs/i18n",
    "dayjs-nuxt",
    '@element-plus/nuxt'
  ],

  dayjs: {
    locales: ["en", "fr"],
    plugins: ["relativeTime", "utc", "timezone"],
    defaultLocale: "en",
    defaultTimezone: "America/New_York",
  },
  elementPlus: {
    // 引入 element-plus 的配置文件
    importStyle: 'scss', // 如果你需要使用 SCSS 样式
  },
  // naive-ui 配置
  build: {
    transpile:
      process.env.NODE_ENV === "production"
        ? [
            "naive-ui",
            "@css-render/vue3-ssr",
            "@juggle/resize-observer",
            "element-plus", // 确保 element-plus 被转译
          ]
        : ["@juggle/resize-observer"],
  },

  vite: {
    optimizeDeps: {
      include:
        process.env.NODE_ENV === "development"
          ? [
              "naive-ui",
              "date-fns-tz/formatInTimeZone",
              "ua-parser-js",
              "md5",
              "dayjs/locale/zh-cn",
              "element-plus", // 确保 element-plus 被优化依赖
            ]
          : [],
    },
  },

  css: [
    "@/assets/css/main.css",
    "@/assets/css/components.css",
    "mavon-editor/dist/css/index.css",
    "@/assets/css/ui.scss",
    "element-plus/dist/index.css", // 引入 element-plus 的样式
  ],

  i18n: {
    vueI18n: "./i18n.config.ts",
  },

  app: {
    head: {
      viewport:
        "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no",
    },
  },

  // 利用Nuxt3集成的服务器引擎Nitro来进行代理转发
  // 代理转发配置：
  nitro: {
    // 该配置用于服务端请求转发
    routeRules: {
      "/api/**": {
        // proxy: "http://localhost:8000/api/**",
        proxy: "https://nestapi.taoqilin.cn/api/**",
      },
    },
  },

  // 配置通用BaseUrl:
  runtimeConfig: {
    // 只在服务器端可用的私有键
    // public中的键也可以在客户端使用
    public: {
      baseUrl: "/api/",
      accessToken: "ACCESS_TOKEN",
    },
  },

  plugins: [
    {
      src: "@/plugins/vueMarkdown.ts",
      mode: "client", // client 表示只在客户端渲染时生效
    },
    {
      src: "@/plugins/vue-lazyload.client.ts",
      mode: "client", // client 表示只在客户端渲染时生效
    },
  ],

  routeRules: {
    // Generated at build time for SEO purpose
    "/": { redirect: { to: "/home", statusCode: 200 } },
    // Cached for 1 hour
    "/api/*": { cache: { maxAge: 60 * 60 } },
  },

  compatibilityDate: "2025-02-20",
});